package com.wenwei.view;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.jakewharton.rxbinding.widget.RxTextView;
import com.orhanobut.logger.Logger;
import com.wenwei.parking.R;

import rx.Observable;
import rx.functions.Action1;
import rx.functions.Func2;

/**
 * Created by Administrator on 2017/07/12 0012.
 */
public class PaySuccessPw extends PopupWindow implements View.OnClickListener {

    Activity mActivity;
    PopupWindow popupWindow;


    public CallBack mCallBack;

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_close:
                mCallBack.onClose();
                popupWindow.dismiss();
                break;
        }
    }

    public interface CallBack{
        void onClose();
    }

    TextView timeTv;
    ImageView closeImg;
    public PaySuccessPw(Activity activity, View parentView, final CallBack callBack) {
        this.mCallBack = callBack;
        mActivity = activity;
        View contentView = LayoutInflater.from(activity).inflate(
                R.layout.custom_login_popup, null);

        closeImg = (ImageView) contentView.findViewById(R.id.iv_close);
        closeImg.setOnClickListener(this);
        timeTv = (TextView) contentView.findViewById(R.id.time_tv);


        popupWindow = new PopupWindow(contentView,
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        popupWindow.setTouchable(true);
        popupWindow.setOutsideTouchable(true);
        ColorDrawable cd = new ColorDrawable(0x000000);
        popupWindow.setBackgroundDrawable(cd);

//        WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
//        lp.alpha = 0.4f;
//        activity.getWindow().setAttributes(lp);

        backgroundAlpha(0.4f);
        popupWindow.showAtLocation(parentView, Gravity.CENTER, 0, 0);
        popupWindow.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss() {
                mCallBack.onClose();
                backgroundAlpha(1f);
            }
        });
    }

    public void backgroundAlpha(float bgAlpha)
    {
        WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
        lp.alpha = bgAlpha; //0.0-1.0
        mActivity.getWindow().setAttributes(lp);
    }

    /**
     * 改变背景颜色
     */
//    private void darkenBackground(Float bgcolor) {
//        WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
//        lp.alpha = bgcolor;
////        mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
//        mActivity.getWindow().setAttributes(lp);
//    }



}
